#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>

int main()
{
    pid_t pid = fork();
    if (pid == 0)
    {
        // 子进程
        printf("Child process exiting.\n");
        _exit(1);
    }
    else if (pid > 0)
    {
        // 父进程
        int status;
        pid_t child_pid = wait(&status);
        printf("%d\n",WIFEXITED(status));
        if (child_pid > 0)
        {
            if (WIFEXITED(status))
            {
                printf("Child process %d exited with status %d.\n", child_pid, WEXITSTATUS(status));
            }
        }
        else
        {
            perror("wait");
        }
    }
    else
    {
        // fork 失败
        perror("fork");
    }
    return 0;
}